home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / shape.lha / shape / put_line.c < prev    next >
Text File  |  1993-08-08  |  525b  |  28 lines

  1. include "screen.h"
  2.  
  3. oid put_line(point a, point b)
  4.  
  5.    put_line(a.x, a.y, b.x, b.y);
  6.  
  7.  
  8. oid put_line(int x0, int y0, int x1, int y1)
  9.  
  10.    register dx = 1;
  11.    int a = x1 - x0;
  12.    if (a < 0) dx = -1, a = -a;
  13.    register dy = 1;
  14.    int b = y1 - y0;
  15.    if (b < 0) dy = -1, b = -b;
  16.    int two_a = 2 * a;
  17.    int two_b = 2 * b;
  18.    int xcrit = -b + two_a;
  19.    register eps = 0;
  20.    for (;;)
  21. {
  22. put_point(x0, y0);
  23. if (x0 == x1 && y0 == y1) break;
  24. if (eps <= xcrit) x0 += dx, eps += two_b;
  25. if (eps>= a || a <= b) y0 += dy, eps -= two_a;
  26. }
  27.  
  28.